package com.qlk.odcinterface.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qlk.odcinterface.domain.PmsChannels;
import com.qlk.odcinterface.domain.query.PmsChannelsQuery;
import com.qlk.odcinterface.manager.PmsChannelsManager;
import com.qlk.odcinterface.service.PmsChannelsService;
import com.qlk.odcinterface.utils.exceptions.ExistedException;
import com.qlk.common.utils.page.PageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.perf4j.aop.Profiled;
 
/**
 * PmsChannelsService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 13:22:58
 * 
 */
@Service
public class PmsChannelsServiceImpl implements PmsChannelsService {

    /** LOG */
    private static final Log LOG = LogFactory.getLog(PmsChannelsServiceImpl.class);

    @Autowired
    private PmsChannelsManager pmsChannelsManager;

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsChannelsService.batchInsert")
    public boolean insert(List<PmsChannels> pmsChannelsList) {
        boolean resultFlag = false;
        try {
            if (CollectionUtils.isNotEmpty(pmsChannelsList)) {
                resultFlag = pmsChannelsManager.insert(pmsChannelsList);
            } else {
                LOG.warn("PmsChannelsServiceImpl#batchInsert failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsChannelsServiceImpl#batchInsert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsChannelsService.insert")
    public boolean insert(PmsChannels pmsChannels) {
        boolean resultFlag = false;
        try {
            if (null != pmsChannels) {
                if (pmsChannelsManager.exist(pmsChannels)) {
                    throw new ExistedException();
                }
                resultFlag = pmsChannelsManager.insert(pmsChannels);
            } else {
                LOG.warn("PmsChannelsServiceImpl#insert failed, param is illegal.");
            }
        } catch (ExistedException e) {
            LOG.warn("PmsChannelsServiceImpl#insert failed, pmsChannels has existed.");
            throw e;
        } catch (Exception e) {
            LOG.error("PmsChannelsServiceImpl#insert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsChannelsService.update")
    public boolean update(PmsChannels pmsChannels) {
        boolean resultFlag = false;
        try {
            if (null != pmsChannels && null != pmsChannels.getId()) {
                resultFlag = pmsChannelsManager.update(pmsChannels);
            } else {
                LOG.warn("PmsChannelsServiceImpl#update failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsChannelsServiceImpl#update has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsChannelsService.queryPmsChannelsList")
    public List<PmsChannels> queryPmsChannelsList(PmsChannelsQuery queryBean) {
        List<PmsChannels> pmsChannelsList = null;
        try {
            pmsChannelsList = pmsChannelsManager.queryPmsChannelsList(queryBean);
        } catch (Exception e) {
            LOG.error("PmsChannelsServiceImpl#queryPmsChannelsList has error.", e);
        }
        return pmsChannelsList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsChannelsService.queryPmsChannelsListWithPage")
    public List<PmsChannels> queryPmsChannelsListWithPage(PmsChannelsQuery queryBean, PageUtil pageUtil) {
        List<PmsChannels> pmsChannelsList = null;
        try {
            pmsChannelsList = pmsChannelsManager.queryPmsChannelsListWithPage(queryBean, pageUtil);
        } catch (Exception e) {
            LOG.error("PmsChannelsServiceImpl#queryPmsChannelsListWithPage has error.", e);
        }
        return pmsChannelsList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsChannelsService.delete")
    public boolean delete(PmsChannels pmsChannels) {
        boolean resultFlag = false;
        try {
            if (null != pmsChannels && null != pmsChannels.getId()) {
                resultFlag = pmsChannelsManager.delete(pmsChannels);
            } else {
                LOG.warn("PmsChannelsServiceImpl#delete param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsChannelsServiceImpl#delete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsChannelsService.batchDelete")
    public boolean delete(PmsChannels[] pmsChannelss) {
        boolean resultFlag = false;
        try {
            if (null != pmsChannelss && pmsChannelss.length > 0) {
                resultFlag = pmsChannelsManager.delete(pmsChannelss);
            } else {
                LOG.warn("PmsChannelsServiceImpl#batchDelete failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsChannelsServiceImpl#batchDelete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsChannelsService.getPmsChannelsById")
    public PmsChannels getPmsChannelsById(Integer id) {
        PmsChannels pmsChannels = null;
        try {
            if (null != id) {
                pmsChannels = pmsChannelsManager.getPmsChannelsById(id);
            } else {
                LOG.warn("PmsChannelsServiceImpl#getPmsChannelsById failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsChannelsServiceImpl#getPmsChannelsById has error.", e);
        }
        return pmsChannels;
    }
}

